import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:native_video_view/native_video_view.dart';

import 'logic.dart';

class VideoPage extends StatelessWidget {
  const VideoPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final logic = Get.find<VideoLogic>();
    return Scaffold(
      backgroundColor: Colors.black,
      body: Center(
        child: NativeVideoView(
          keepAspectRatio: true,
          showMediaController: true,
          onCreated: (controller) {
            controller.setVideoSource(
              logic.videoUrl,
              sourceType: VideoSourceType.network,
            );
          },
          onPrepared: (controller, info) {
            print("开始播放");
            controller.play();
          },
          onError: (controller, what, extra, message) {
            print('Player Error ($what | $extra | $message)');
            EasyLoading.showToast("播放出错");
          },
          onCompletion: (controller) {
            print('Video completed');
          },
          onProgress: (progress, duration) {
            print('$progress | $duration');
          },
        ),
      ),
    );
  }
}
